package com.example.lab03.service;

import com.example.lab03.entity.User;
import com.example.lab03.repository.UserRepository;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    private final UserRepository userRepository;

    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public List<User> queryAll() {
        return userRepository.findAll();
    }
    public User create(User user){
        userRepository.save(user);
        return user;
    }
    public User queryById(String id){
        return userRepository.findById(id).orElse(null);
    }
    public User modify(User user){
        return userRepository.save(user);
    }
    public String removeById(String id){
         userRepository.deleteById(id);
         return id;
    }
}
